package com.ruoyi.project.module.lyx;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.project.domain.YqgCheckoutMethod;
import com.ruoyi.project.domain.YqgConsumptionDetails;
import com.ruoyi.project.module.lyx.lei.Category;
import com.ruoyi.project.module.lyx.lei.Department;
import com.ruoyi.project.module.lyx.lei.Jiezhang;
import com.ruoyi.project.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * 消费详细Controller
 * 
 * @author dr
 * @date 2023-04-17
 */
@RestController
@RequestMapping("/lyx/baobiao")
public class LyxYqgBaobiaoController extends BaseController
{
    @Autowired
    private IYqgConsumptionDetailsService yqgConsumptionDetailsService;
    @Autowired
    private IYqgCheckoutMethodService yqgCheckoutMethodService;
    @Autowired
    private IYqgBarBillsService yqgBarBillsService;
    @Autowired
    private IYqgHandsService yqgHandsService;
    @Autowired
    private IYqgInformationRoomService yqgInformationRoomService;
    @Autowired
    private IYqgInformationProjectService yqgInformationProjectService;

    /**
     * 查询消费详细列表
     */

    //@RequiresPermissions("project:details:list")
    @GetMapping("/list")
    public TableDataInfo list(YqgConsumptionDetails yqgConsumptionDetails) {
        return getDataTable(handleInfo(yqgConsumptionDetails));    //handleInfo是随意起的方法名字，此处是指将最后查询完的结果传回消费详细表
    }
    public List<Category> handleInfo(YqgConsumptionDetails yqgConsumptionDetails){//<内部的Chargeback>是定义的类，是module/lyx/lei下chargeback.java里面定义的

        List<YqgConsumptionDetails> list = yqgConsumptionDetailsService.selectYqgConsumptionDetailsList(yqgConsumptionDetails);
        List<Category> shopList = new ArrayList<>();
        int a=0;
        for(int i =0;i<list.size();i++){
            if(list.get(i).getProjectCategory().equals("04")){
                a+=Integer.parseInt(list.get(i).getTotalAmount());
            }
            if(list.get(i).getProjectCategory().equals("05")){
                a+=Integer.parseInt(list.get(i).getTotalAmount());
            }
            if(list.get(i).getProjectCategory().equals("07")){
                a+=Integer.parseInt(list.get(i).getTotalAmount());
            }
            if(list.get(i).getProjectCategory().equals("08")){
                a+=Integer.parseInt(list.get(i).getTotalAmount());
            }
        }
        Category categoryshop = new Category();
        categoryshop.setCategory("商品");
        categoryshop.setIncome(String.valueOf(a));
        shopList.add(categoryshop);
        List<Category> menpiaoList = new ArrayList<>();
        int b=0;
        for(int i =0;i<list.size();i++){
            if(list.get(i).getProjectCategory().equals("01")){
                b+=Integer.parseInt(list.get(i).getTotalAmount());
            }
        }
        Category categorymenpiao = new Category();
        categorymenpiao.setCategory("门票");
        categorymenpiao.setIncome(String.valueOf(b));
        menpiaoList.add(categorymenpiao);
        shopList.addAll(menpiaoList);
        return shopList;
    }
    /**
     * 查询结账详细列表
     */
//    @RequiresPermissions("project:details:list")
    @GetMapping("/listjiezhang")
    public TableDataInfo list1(YqgCheckoutMethod yqgCheckoutMethod) {
        return getDataTable(handleInfo1(yqgCheckoutMethod));    //handleInfo是随意起的方法名字，此处是指将最后查询完的结果传回消费详细表
    }
    public List<Jiezhang> handleInfo1(YqgCheckoutMethod yqgCheckoutMethod){
        //查询所有
        List<YqgCheckoutMethod> list = yqgCheckoutMethodService.selectYqgCheckoutMethodList(yqgCheckoutMethod);

//        long startTime = Long.parseLong(yqgConsumptionDetails.getNote1()) + 9 * 60 * 60 * 1000;
//        long startTime = Long.parseLong(yqgConsumptionDetails.getNote1());

        //用新的实体类来操作
        int b =0;
        List<Jiezhang> xianjinList = new ArrayList<>();
        Jiezhang jiezhang=new Jiezhang();
        for (int i=0;i<list.size();i++){
            if(list.get(i).getPaymentMethod().equals("0")){
                b+=Integer.parseInt(list.get(i).getPaymentAmount());
            }
        }
        jiezhang.setPaymentMethod("现金");
        jiezhang.setMoney(String.valueOf(b));
        xianjinList.add(jiezhang);
//        return xianjinList;
        //用新的实体类来操作
        int c =0;
        List<Jiezhang> xinyongkaList = new ArrayList<>();
        Jiezhang jiezhangxin=new Jiezhang();
        for (int i=0;i<list.size();i++){
            if(list.get(i).getPaymentMethod().equals("1")){
                c+=Integer.parseInt(list.get(i).getPaymentAmount());
            }
        }
        jiezhangxin.setPaymentMethod("信用卡");
        xinyongkaList.add(jiezhangxin);
        jiezhangxin.setMoney(String.valueOf(c));
        xianjinList.addAll(xinyongkaList);
        //用新的实体类来操作
        int d=0;
        List<Jiezhang> canquanList = new ArrayList<>();
        Jiezhang jiezhangcan=new Jiezhang();
        for (int i=0;i<list.size();i++){
            if(list.get(i).getPaymentMethod().equals("2")){
                d+=Integer.parseInt(list.get(i).getPaymentAmount());
            }
        }
        jiezhangcan.setPaymentMethod("餐券");
        jiezhangcan.setMoney(String.valueOf(d));
        canquanList.add(jiezhangcan);
        xianjinList.addAll(canquanList);
        //用新的实体类来操作
        int e=0;
        List<Jiezhang> guazhangList = new ArrayList<>();
        Jiezhang jiezhanggua=new Jiezhang();
        for (int i=0;i<list.size();i++){
            if(list.get(i).getPaymentMethod().equals("3")){
                e+=Integer.parseInt(list.get(i).getPaymentAmount());
            }
        }
        jiezhanggua.setPaymentMethod("挂账");
        jiezhanggua.setMoney(String.valueOf(e));
        guazhangList.add(jiezhanggua);
        xianjinList.addAll(guazhangList);
        //用新的实体类来操作
        int f=0;
        List<Jiezhang> miandanList = new ArrayList<>();
        Jiezhang jiezhangmian=new Jiezhang();
        for (int i=0;i<list.size();i++){
            if(list.get(i).getPaymentMethod().equals("4")){
                f+=Integer.parseInt(list.get(i).getPaymentAmount());
            }
        }
        jiezhangmian.setPaymentMethod("免单");
        jiezhangmian.setMoney(String.valueOf(f));
        miandanList.add(jiezhangmian);
        xianjinList.addAll(miandanList);
        //用新的实体类来操作
        int g=0;
        List<Jiezhang> menpiao1List = new ArrayList<>();
        Jiezhang jiezhangmen=new Jiezhang();
        for (int i=0;i<list.size();i++){
            if(list.get(i).getPaymentMethod().equals("5")){
                g+=Integer.parseInt(list.get(i).getPaymentAmount());
            }
        }
        jiezhangmen.setPaymentMethod("门票");
        jiezhangmen.setMoney(String.valueOf(g));
        menpiao1List.add(jiezhangmen);
        xianjinList.addAll(menpiao1List);
        //用新的实体类来操作
        int h=0;
        List<Jiezhang> meituanList = new ArrayList<>();
        Jiezhang jiezhangmei=new Jiezhang();
        for (int i=0;i<list.size();i++){
            if(list.get(i).getPaymentMethod().equals("6")){
                h+=Integer.parseInt(list.get(i).getPaymentAmount());
            }
        }
        jiezhangmei.setPaymentMethod("美团");
        jiezhangmei.setMoney(String.valueOf(h));
        meituanList.add(jiezhangmei);
        xianjinList.addAll(meituanList);
        //用新的实体类来操作
        int j=0;
        List<Jiezhang> huiyuanList = new ArrayList<>();
        Jiezhang jiezhanghui=new Jiezhang();
        for (int i=0;i<list.size();i++){
            if(list.get(i).getPaymentMethod().equals("7")){
                j+=Integer.parseInt(list.get(i).getPaymentAmount());
            }
        }
        jiezhanghui.setPaymentMethod("会员卡");
        jiezhanghui.setMoney(String.valueOf(j));
        huiyuanList.add(jiezhanghui);
        xianjinList.addAll(huiyuanList);
        //用新的实体类来操作
        int k=0;
        List<Jiezhang> dianziList = new ArrayList<>();
        Jiezhang jiezhangdian=new Jiezhang();
        for (int i=0;i<list.size();i++){
            if(list.get(i).getPaymentMethod().equals("8")){
                k+=Integer.parseInt(list.get(i).getPaymentAmount());
            }
        }
        jiezhangdian.setPaymentMethod("电子券");
        jiezhangdian.setMoney(String.valueOf(k));
        dianziList.add(jiezhangdian);
        xianjinList.addAll(dianziList);
        //用新的实体类来操作
        int l=0;
        List<Jiezhang> dianzicanList = new ArrayList<>();
        Jiezhang jiezhangdiancan=new Jiezhang();
        for (int i=0;i<list.size();i++){
            if(list.get(i).getPaymentMethod().equals("9")){
                l+=Integer.parseInt(list.get(i).getPaymentAmount());
            }
        }
        jiezhangdiancan.setPaymentMethod("电子餐券");
        jiezhangdiancan.setMoney(String.valueOf(l));
        dianzicanList.add(jiezhangdiancan);
        xianjinList.addAll(dianzicanList);
        //用新的实体类来操作
        int m=0;
        List<Jiezhang> wechatList = new ArrayList<>();
        Jiezhang jiezhangwe=new Jiezhang();
        for (int i=0;i<list.size();i++){
            if(list.get(i).getPaymentMethod().equals("10")){
                m+=Integer.parseInt(list.get(i).getPaymentAmount());
            }
        }
        jiezhangwe.setPaymentMethod("微信团购");
        jiezhangwe.setMoney(String.valueOf(m));
        wechatList.add(jiezhangwe);
        xianjinList.addAll(wechatList);
        //用新的实体类来操作
        int n=0;
        List<Jiezhang> zhifuList = new ArrayList<>();
        Jiezhang jiezhangzhi=new Jiezhang();
        for (int i=0;i<list.size();i++){
            if(list.get(i).getPaymentMethod().equals("11")){
                n+=Integer.parseInt(list.get(i).getPaymentAmount());
            }
        }
        jiezhangzhi.setPaymentMethod("支付宝");
        jiezhangzhi.setMoney(String.valueOf(n));
        zhifuList.add(jiezhangzhi);
        xianjinList.addAll(zhifuList);
        //用新的实体类来操作
        int o=0;
        List<Jiezhang> huoList = new ArrayList<>();
        Jiezhang jiezhanghuo=new Jiezhang();
        for (int i=0;i<list.size();i++){
            if(list.get(i).getPaymentMethod().equals("12")){
                o+=Integer.parseInt(list.get(i).getPaymentAmount());
            }
        }
        jiezhanghuo.setPaymentMethod("活动赠票");
        jiezhanghuo.setMoney(String.valueOf(o));
        huoList.add(jiezhanghuo);
        xianjinList.addAll(huoList);
        //用新的实体类来操作
        int p=0;
        List<Jiezhang> banList = new ArrayList<>();
        Jiezhang jiezhangban=new Jiezhang();
        for (int i=0;i<list.size();i++){
            if(list.get(i).getPaymentMethod().equals("13")){
                p+=Integer.parseInt(list.get(i).getPaymentAmount());
            }
        }
        jiezhangban.setPaymentMethod("办卡赠票");
        jiezhangban.setMoney(String.valueOf(p));
        banList.add(jiezhangban);
        xianjinList.addAll(banList);
        //用新的实体类来操作
        int q=0;
        List<Jiezhang> dangList = new ArrayList<>();
        Jiezhang jiezhangdang=new Jiezhang();
        for (int i=0;i<list.size();i++){
            if(list.get(i).getPaymentMethod().equals("14")){
                q+=Integer.parseInt(list.get(i).getPaymentAmount());
            }
        }
        jiezhangdang.setPaymentMethod("当天赠票");
        jiezhangdang.setMoney(String.valueOf(q));
        dangList.add(jiezhangdang);
        xianjinList.addAll(dangList);
        //用新的实体类来操作
        int r=0;
        List<Jiezhang> dangcanList = new ArrayList<>();
        Jiezhang jiezhangdangcan=new Jiezhang();
        for (int i=0;i<list.size();i++){
            if(list.get(i).getPaymentMethod().equals("15")){
                r+=Integer.parseInt(list.get(i).getPaymentAmount());
            }
        }
        jiezhangdangcan.setPaymentMethod("当天赠餐券");
        jiezhangdangcan.setMoney(String.valueOf(r));
        dangcanList.add(jiezhangdangcan);
        xianjinList.addAll(dangcanList);
        //用新的实体类来操作
        int s=0;
        List<Jiezhang> ciList = new ArrayList<>();
        Jiezhang jiezhangdangci=new Jiezhang();
        for (int i=0;i<list.size();i++){
            if(list.get(i).getPaymentMethod().equals("16")){
                s+=Integer.parseInt(list.get(i).getPaymentAmount());
            }
        }
        jiezhangdangci.setPaymentMethod("门票次卡");
        jiezhangdangci.setMoney(String.valueOf(s));
        ciList.add(jiezhangdangci);
        xianjinList.addAll(ciList);
        return xianjinList;
    }
    /**
     * 查询部门列表
     */
//    @RequiresPermissions("project:details:list")
    @GetMapping("/listbumen")
    public TableDataInfo list2(YqgConsumptionDetails yqgConsumptionDetails) {
        return getDataTable(handleInfo2(yqgConsumptionDetails));    //handleInfo是随意起的方法名字，此处是指将最后查询完的结果传回消费详细表
    }
    public List<Department> handleInfo2(YqgConsumptionDetails yqgConsumptionDetails){
        //查询所有
        List<YqgConsumptionDetails> list = yqgConsumptionDetailsService.selectYqgConsumptionDetailsList(yqgConsumptionDetails);
        //用新的实体类来操作
        int a=0;
        List<Department> bumenList = new ArrayList<>();
        Department department= new Department();
        for (int i=0;i<list.size();i++){
            if(list.get(i).getDepartment().equals("0")){
                a+=Integer.parseInt(list.get(i).getTotalAmount());
            }
        }
        department.setDepartment("洗浴部门");
        department.setAmount(String.valueOf(a));
        bumenList.add(department);
        //用新的实体类来操作
        int b =0;
        List<Department> bumenList1 = new ArrayList<>();
        Department departmentcan= new Department();
        for (int i=0;i<list.size();i++){
            if(list.get(i).getDepartment().equals("1")){
                b+=Integer.parseInt(list.get(i).getTotalAmount());
            }
        }
        departmentcan.setDepartment("餐饮部门");
        departmentcan.setAmount(String.valueOf(b));
        bumenList1.add(departmentcan);
        bumenList.addAll(bumenList1);
        //用新的实体类来操作
        int c=0;
        List<Department> bumenList2 = new ArrayList<>();
        Department departmentshop= new Department();
        for (int i=0;i<list.size();i++){
            if(list.get(i).getDepartment().equals("2")){
                c+=Integer.parseInt(list.get(i).getTotalAmount());
            }
        }
        departmentshop.setDepartment("商品部门");
        departmentshop.setAmount(String.valueOf(c));
        bumenList2.add(departmentshop);
        bumenList.addAll(bumenList2);
        //用新的实体类来操作
        int d=0;
        List<Department> bumenList3 = new ArrayList<>();
        Department departmentqian= new Department();
        for (int i=0;i<list.size();i++){
            if(list.get(i).getDepartment().equals("3")){
                d+=Integer.parseInt(list.get(i).getTotalAmount());
            }
        }
        departmentqian.setDepartment("前台部门");
        departmentqian.setAmount(String.valueOf(d));
        bumenList3.add(departmentqian);
        bumenList.addAll(bumenList3);
        //用新的实体类来操作
        int e=0;
        List<Department> bumenList4 = new ArrayList<>();
        Department departmentjishi= new Department();
        for (int i=0;i<list.size();i++){
            if(list.get(i).getDepartment().equals("4")){
                e+=Integer.parseInt(list.get(i).getTotalAmount());
            }
        }
        departmentjishi.setDepartment("技师部门");
        departmentjishi.setAmount(String.valueOf(e));
        bumenList4.add(departmentjishi);
        bumenList.addAll(bumenList4);
        //用新的实体类来操作
        int f=0;
        List<Department> bumenList5 = new ArrayList<>();
        Department departmentkefang= new Department();
        for (int i=0;i<list.size();i++){
            if(list.get(i).getDepartment().equals("5")){
                f+=Integer.parseInt(list.get(i).getTotalAmount());
            }
        }
        departmentkefang.setDepartment("客房部门");
        departmentkefang.setAmount(String.valueOf(f));
        bumenList5.add(departmentkefang);
        bumenList.addAll(bumenList5);
        return bumenList;
    }

    /**
     * 导出消费详细列表
     */
    @RequiresPermissions("project:details:export")
    @Log(title = "导出", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YqgConsumptionDetails yqgConsumptionDetails)
    {
        List<YqgConsumptionDetails> list = yqgConsumptionDetailsService.selectYqgConsumptionDetailsList(yqgConsumptionDetails);
        ExcelUtil<YqgConsumptionDetails> util = new ExcelUtil<YqgConsumptionDetails>(YqgConsumptionDetails.class);
        util.exportExcel(response, list, "消费详细数据");
    }
    /**
     * 这段代码是一个方法，用于导出消费详细数据到Excel文件中。具体的实现逻辑是：
     * 1.通过调用yqgConsumptionDetailsService的selectYqgConsumptionDetailsList方法获取消费详细数据的列表。
     * 2.创建一个ExcelUtil对象，该对象可以将List对象导出到Excel文件中。
     * 3.调用ExcelUtil的exportExcel方法，将消费详细数据列表导出到Excel文件中。
     * 4.将Excel文件通过HttpServletResponse对象返回给前端，文件名为"消费详细数据"。
     */

    /**
     * 获取消费详细详细信息
     */
    @RequiresPermissions("project:details:query")
    @GetMapping(value = "/{ID}")
    public AjaxResult getInfo(@PathVariable("ID") Long ID)
    {
        return success(yqgConsumptionDetailsService.selectYqgConsumptionDetailsByID(ID));
    }
    /**
     * 这段代码是一个Spring Boot的接口，接收一个ID作为参数，并通过调用yqgConsumptionDetailsService的selectYqgConsumptionDetailsByID方法来查询相应的信息。最后，将查询结果封装成AjaxResult对象并返回。
     */



    /**
     * 新增消费详细
     */
    @RequiresPermissions("project:details:add")
    @Log(title = "新增", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YqgConsumptionDetails yqgConsumptionDetails)
    {
        return toAjax(yqgConsumptionDetailsService.insertYqgConsumptionDetails(yqgConsumptionDetails));
    }
    /**
     *这段代码是一个Java方法，它接收一个名为yqgConsumptionDetails的参数，
     * 并将其作为RequestBody传递给add方法。
     * 方法体内部会调用yqgConsumptionDetailsService的insertYqgConsumptionDetails方法，
     * 并将结果转换为AjaxResult类型返回。
     */



    /**
     * 修改消费详细
     */
    @RequiresPermissions("project:details:edit")
    @Log(title = "修改", businessType = BusinessType.UPDATE)
    @PutMapping("/pp")
    public AjaxResult edit(@RequestBody YqgConsumptionDetails yqgConsumptionDetails)
    {
        System.out.println("1000000");
        return toAjax(yqgConsumptionDetailsService.updateYqgConsumptionDetails(yqgConsumptionDetails));
    }
   /**
    * 这段代码是一个Java方法，它接收一个名为yqgConsumptionDetails的参数，
    *   并将其作为RequestBody传递给edit方法。方法体内部会打印出"1000000"，
    *   然后调用yqgConsumptionDetailsService的updateYqgConsumptionDetails方法，
    *   并将结果转换为AjaxResult类型返回。
    *
    *    @RequestBody主要用来接收前端传递给后端的json字符串中的数据的(请求体中的数据的)；
    *    而最常用的使用请求体传参的是POST请求，所以使用@RequestBody接收数据时，一般都用POST方式进行提交。
    *    在后端的同一个接收方法里，@RequestBody与@RequestParam()可以同时使用，@RequestBody最多只能有一个，而@RequestParam()可以有多个。
    * /



    /**
     * 删除消费详细
     */
    @RequiresPermissions("project:details:remove")
    @Log(title = "删除", businessType = BusinessType.DELETE)
	@DeleteMapping("/{IDs}")
    public AjaxResult remove(@PathVariable Long[] IDs)
    {
        return toAjax(yqgConsumptionDetailsService.deleteYqgConsumptionDetailsByIDs(IDs));
    }
    /**
     * 这段代码是一个Java方法，它接收一个名为IDs的参数，并将其作为PathVariable传递给remove方法。
     * 方法体内部会调用yqgConsumptionDetailsService的deleteYqgConsumptionDetailsByIDs方法，
     * 并将结果转换为AjaxResult类型返回。
     */





}
